package com.bootdo.system.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bootdo.common.utils.DateUtils;
import com.bootdo.system.domain.TbWallet;
import com.bootdo.system.domain.TbWalletExample;
import com.bootdo.system.mapper.TbWalletMapper;
import com.bootdo.system.service.WalletService;

@Service
public class WalletServiceImpl implements WalletService{
	@Autowired
    private TbWalletMapper sm;
	@Override
	public TbWallet getWall() {
		TbWalletExample tbWalletExample = new TbWalletExample();
		List<TbWallet> selectByExample = sm.selectByExample(tbWalletExample);
		if(selectByExample.size() > 0) {
			return selectByExample.get(0);
		}
		return null;
	}

	@Override
	public int insert2update(TbWallet table) {
		int res=0;
		if(table != null) {
			Integer id = table.getId();
			if(id != null) {
				table.setXgsj(DateUtils.format(new Date()));
				res=sm.updateByPrimaryKeySelective(table);
			}else {
				res=sm.insertSelective(table);
			}
		}
		return res;
	}

	@Override
	public TbWallet getById(Integer id) {
		return sm.selectByPrimaryKey(id);
	}

}
